package com.odin.backgrounddownload;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class SGActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {

    public interface BooleanChangedCallbacks {
        void onFocusChanged(boolean newValue);
    }

    private BooleanChangedCallbacks m_AppFocusListener;

    public SGActivityLifecycleCallbacks(BooleanChangedCallbacks listener)
    {
        setOnAppFocusListener(listener);
    }

    @Override
    public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {

    }

    @Override
    public void onActivityStarted(@NonNull Activity activity) {

    }

    @Override
    public void onActivityResumed(@NonNull Activity activity) {
        if (m_AppFocusListener != null)
        {
            m_AppFocusListener.onFocusChanged(true);
        }
    }

    @Override
    public void onActivityPaused(@NonNull Activity activity) {

    }

    @Override
    public void onActivityStopped(@NonNull Activity activity) {
        if (m_AppFocusListener != null)
        {
            m_AppFocusListener.onFocusChanged(false);
        }
    }

    @Override
    public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {

    }

    @Override
    public void onActivityDestroyed(@NonNull Activity activity) {

    }

    // 设置事件监听器的方法
    public void setOnAppFocusListener(BooleanChangedCallbacks listener) {
        this.m_AppFocusListener = listener;
    }

}
